package com.meowcook.controller;

import com.meowcook.config.AppConfig;
import com.meowcook.common.AppResult;
import com.meowcook.pojo.dto.HealthInfoDTO;
import com.meowcook.pojo.vo.UserPartIVO;
import com.meowcook.service.IHealthInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28792
 * Date: 2025-04-29
 * Time: 21:36
 */
@Slf4j
@Api(tags = "健康信息操作接口")
@RestController
@RequestMapping("/healthInfo")
public class HealthInfoController {

    @Resource
    private IHealthInfoService healthInfoService;

    @ApiOperation("健康信息采集")
    @PostMapping("/storeHealthInfo")
    public AppResult storeHealthInfo(HttpServletRequest request, @Valid @RequestBody HealthInfoDTO healthInfo) {
        log.info("健康信息：{}", healthInfo);
        // 获取用户ID
        UserPartIVO user = (UserPartIVO) request.getSession(false).getAttribute(AppConfig.USER_SESSION_KEY);
        Long userId = user.getId();
        // 调用Service
        healthInfoService.storeOne(healthInfo, userId);
        return AppResult.success("采集成功");
    }
}
